<template>
  <div class="main">

    <!--搜索部分-->
    <div class="user-search-container">



      <el-form ref="params" :inline="true" v-show="true" label-width="68px">
        <el-form-item label="id" prop="id">
          <el-input v-model="params.id" placeholder="请输入邀请码id" clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="用户编号" prop="userId">
          <el-input v-model="params.userId" placeholder="请输入用户编号" clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery" />
        </el-form-item>

        <el-form-item label="创建时间">
          <el-date-picker v-model="dateRange" size="small" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="cyan" icon="el-icon-search" size="mini" @click="queryList(true)">搜索</el-button>
        </el-form-item>
      </el-form>

    </div>

    <!--列表部分-->
    <div class="user-list-container">

      <van-divider />

      <el-table v-loading="loading" :data="list">
        <el-table-column type="selection" width="50" align="center" />
        <el-table-column label="id" align="center" prop="id"/>
        <el-table-column label="用户编号" align="center" prop="userId"/>
        <el-table-column label="总收益" align="center" prop="totalProfit"/>
        <el-table-column label="账户余额" align="center" prop="balance"/>
        <el-table-column label="创建时间" align="center" prop="createTime"/>


        <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <!--<el-button size="mini" type="text" icon="el-icon-edit" @click="handleDetail(scope.row)">详情</el-button>-->
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total>0" :total="total" :page.sync="params.page" :limit.sync="params.limit" @pagination="onLoad" />
    </div>


  </div>
</template>
<script>
  import { accountPage, inviteCodeAdd} from '@/api/friend';
  import commentUtil from "@/utils/commentUtil";
  import {SUCCESS, SWITCH_TYPE} from "../../../comm/constant";

  export default {


    data() {
      return {
        params:{
          id: null,
          userId: null,
          startTime: null,
          endTime: null,
          limit: 10,
          page: 1,
        },
        SWITCH_TYPE:SWITCH_TYPE,
        dateRange: [],
        total:0,
        list: [],
        loading: false,
        isLoading: false,
        showAdd: false,
        count: false,

      }
    },
    methods: {

      queryList(isSearch){//
        if(this.isLoading) return;
        this.isLoading = true;
        if(isSearch)this.params.page = 1;
        //时间初始化
        if(this.dateRange && this.dateRange.length > 0){
          this.params.startTime = commentUtil.formatStartDate(this.dateRange[0]);
          this.params.endTime = commentUtil.formatEndDate(this.dateRange[1]);
        }else {
          this.params.startTime = null;
          this.params.endTime = null;
        }

        accountPage(this.params).then(res => {
          if(res.code!==SUCCESS){
            this.$notify({ type: 'danger', message: res.msg });
            return;
          }
          this.list = res.data.records;
          this.total = res.data.total;
          this.loading = false;
          this.isLoading = false;
        });
      },
      onClickLeft() {
        this.$router.go(-1);
      },
      onLoad() {
        console.info("加载数据中 第" + this.params.page + "页" );
        this.queryList(false)
      },
    },
    mounted() {
      this.onLoad();
    },

  }
</script>
<style scoped>


  .user-search-container, .user-list-container{
    margin: 8px 17px;
  }
  .user-search-container .van-cell{
    margin: 8px 0px;
  }

  .user-search-container .van-dropdown-menu{
    height: 40px;
    margin: 8px 0px;
  }
  .user-search-container .van-button{
    height: 85px;
    width: 100px;
    background-color: #eeeeee;
    margin: 8px 0px;
  }
  .user-search-container .van-field, .user-search-container .van-cell{
    border: 1px solid #eeeeee;
  }
</style>
